package com.sjgtw.cloud.web.warningSign.controller;

import com.sjgtw.cloud.common.core.web.controller.BaseController;
import com.sjgtw.cloud.common.core.web.domain.AjaxResult;
import com.sjgtw.cloud.common.core.web.page.TableDataInfo;
import com.sjgtw.cloud.util.EasyExcelUtil;
import com.sjgtw.cloud.web.warningSign.domain.WarningSigns;
import com.sjgtw.cloud.web.warningSign.service.IWarningSignsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 防洪警示标志Controller
 * 
 * @author ruoyi
 * @date 2024-03-11
 */
@RestController
@Api(tags = "1.8、防洪警示标志")
@RequestMapping("/warningSign")
public class WarningSignsController extends BaseController
{
    @Autowired
    private IWarningSignsService warningSignsService;

    /**
     * 查询防洪警示标志列表
     */
    //@RequiresPermissions("system:signs:list")
    @GetMapping("/list")
    @ApiOperation("列表")
    public TableDataInfo list(WarningSigns warningSigns)
    {
        startPage();
        List<Map<String,Object>>  list = warningSignsService.selectWarningSignsList(warningSigns);
        return getDataTable(list);
    }

    /**
     * 导出防洪警示标志列表
     */
    //@RequiresPermissions("system:signs:export")
   // @Log(title = "防洪警示标志", businessType = BusinessType.EXPORT)
/*    @PostMapping("/export")
    public void export(HttpServletResponse response, WarningSigns warningSigns)
    {
        List<WarningSigns> list = warningSignsService.selectWarningSignsList(warningSigns);
        ExcelUtil<WarningSigns> util = new ExcelUtil<WarningSigns>(WarningSigns.class);
        util.exportExcel(response, list, "防洪警示标志数据");
    }*/

    /**
     * 获取防洪警示标志详细信息
     */
    //@RequiresPermissions("system:signs:query")
    @GetMapping(value = "/getInfo/{id}")
    @ApiOperation("获取防洪警示标志详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(warningSignsService.selectWarningSignsById(id));
    }

    /**
     * 新增防洪警示标志
     */
    //@RequiresPermissions("system:signs:add")
    //@Log(title = "防洪警示标志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增")
    public AjaxResult add(@RequestBody WarningSigns warningSigns)
    {
        return toAjax(warningSignsService.insertWarningSigns(warningSigns));
    }

    /**
     * 修改防洪警示标志
     */
    //@RequiresPermissions("system:signs:edit")
   // @Log(title = "防洪警示标志", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody WarningSigns warningSigns)
    {
        return toAjax(warningSignsService.updateWarningSigns(warningSigns));
    }

    /**
     * 删除防洪警示标志
     */
    //@RequiresPermissions("system:signs:remove")
   // @Log(title = "防洪警示标志", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{id}")
    @ApiOperation("列表")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(warningSignsService.deleteWarningSignsById(id));
    }


    /**
     * 导出
     */
    @ApiOperation(value = "导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarningSigns warningSigns)
    {
        List<WarningSigns> list = warningSignsService.selectWarningSignsList2(warningSigns);
        EasyExcelUtil<WarningSigns> util = new EasyExcelUtil<>(WarningSigns.class);
        util.exportExcel(response, list, "防洪警示标志", "防洪警示标志", "warningSigns.xlsx");
    }

    /**
     * 下载模版
     */
    @ApiOperation(value = "下载模版")
    @PostMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletResponse response)
    {
        EasyExcelUtil<WarningSigns> util = new EasyExcelUtil<>(WarningSigns.class);
        util.exportExcel(response, new ArrayList<>(), "防洪警示标志", "防洪警示标志模版", "warningSigns.xlsx");
    }

    /**
     * 导入
     */
    @ApiOperation(value = "导入")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file)
    {
        EasyExcelUtil<WarningSigns> util = new EasyExcelUtil<>(WarningSigns.class);
        List<WarningSigns> entities = util.readExcel(file, 0, 1);
        if (entities == null || entities.size() == 0) {
            return error("没有读取到数据");
        }

        List<String> errors = warningSignsService.check(entities);
        if (errors.size() > 0) {
            return AjaxResult.error("", errors);
        }
        warningSignsService.batchSave(entities);
        return success();
    }

}
